package com.cortex.pineapple.database;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import android.graphics.Bitmap;

import com.cortex.pineapple.adapters.ItemList;
import com.cortex.pineapple.adapters.Item;
import com.cortex.pineapple.fetch.FetchIcons;
import com.cortex.pineapple.fetch.FetchIcons.OnFetchIconsChangedListener;
import com.cortex.pineapple.fetch.RequestData.SOURCE_TYPE;
import com.cortext.pineapple.link.Link;
import com.cortext.pineapple.link.Link.OnDataChangedListener;

public class VisitLink implements Item{

	private long id = -1;
	private long idSeason;
	private Date startVisit;
	private String url,title,description;
	private SOURCE_TYPE source;
	private boolean isFavorite;
	private Bitmap favicon;
	private List<String> sectionsSelected;

	public VisitLink() {

	}
	public VisitLink(long idSeason, Date startVisit, String url,
			String title, String description, SOURCE_TYPE source,Bitmap favicon,List<String> sectionsSelected) {
		this.idSeason = idSeason;
		this.startVisit = startVisit;
		this.url = url;
		this.title = title;
		this.description = description;
		this.source = source;
	}
	public VisitLink(long id, long idSeason, Date startVisit, String url,
			String title, String description, SOURCE_TYPE source,boolean isFavorite,Bitmap favicon,List<String> sectionsSelected) {
		this(idSeason, startVisit, url, title, description, source, favicon,sectionsSelected);
		this.id = id;

	}
	
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public long getIdSeason() {
		return idSeason;
	}

	public void setIdSeason(long idSeason) {
		this.idSeason = idSeason;
	}

	public Date getStartVisit() {
		return startVisit;
	}

	public void setStartVisit(Date enteredVisit) {
		this.startVisit = enteredVisit;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	public SOURCE_TYPE getSource() {
		return source;
	}
	public void setSource(SOURCE_TYPE source) {
		this.source = source;
	}
	public boolean isFavorite() {
		return isFavorite;
	}
	public void setFavorite(boolean isFavorite) {
		this.isFavorite = isFavorite;
	}
	public boolean isEmpty(){
		return title.isEmpty() && description.isEmpty();
	}
	public Bitmap getFavicon() {
		return favicon;
	}
	public void setFavicon(Bitmap favicon) {
		this.favicon = favicon;
	}
	public List<String> getSectionsSelected() {
		if(sectionsSelected == null){
			sectionsSelected = new ArrayList<String>();
		}
		return sectionsSelected;
	}
	public void setSectionsSelected(List<String> sectionsSelected) {
		this.sectionsSelected = sectionsSelected;
	}
	@Override
	public boolean equals(Object o) {
		if(o instanceof VisitLink){
			VisitLink visitLink = (VisitLink)o;
			return id == visitLink.getId() || url.equals(visitLink.getUrl());
		}
		return false;
	}
	@Override
	public String toString() {
		return "VisitLink [id=" + id + ", idSeason=" + idSeason
				+ ", enterVisit=" + startVisit + ", url=" + url + ", title="
				+ title + ", description=" + description + ", source=" + source
				+ "]";
	}


	@Override
	public boolean isHeader() {
		return false;
	}


	@Override
	public Object getData() {
		return this;
	}


	@Override
	public Date getDate() {
		return startVisit;
	}


	@Override
	public ITEM_TYPE getType() {
		return ITEM_TYPE.ITEM;
	}

	public interface OnDataChangedListener{
		void dataChanged(VisitLink visitLink);
	}

}
